package fr.inserm.u915.organifooyi.model;

import java.util.Date;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;


@Entity(name="postit")
@Table(name="postit")
@NamedQueries({
    @NamedQuery(name="postitFindByTableAndId",
                query="select p from postit as p where p.foreignId= :foreignId and p.foreignTable= :foreignTable ORDER BY p.creation")

})
public class PostIt extends AbstractUpdatableObject
	{
	@Column(name="foreign_id")
	private Long foreignId;
	@Column(name="foreign_table")
	private String foreignTable;
	@Column(name="enabled")
	private short enabled=1;
	@Column(name="cssStyle")
	private String cssStyle="";
	@Column(name="content")
	private String content="";

	
	public String getCssStyle() {
		return cssStyle;
		}
	
	public void setCssStyle(String cssStyle)
		{
		this.cssStyle = cssStyle;
		}
	
	public short getEnabled() {
		return enabled;
		}
	
	public String getContent() {
		return content;
		}
	
	public void setContent(String content)
		{
		this.content = content;
		}

	
	public Long getForeignId() {
		return foreignId;
	}

	public void setForeignId(Long foreignId) {
		this.foreignId = foreignId;
	}

	public  String getForeignTable() {
		return foreignTable;
	}

	public  void setForeignTable(String foreignTable) {
		this.foreignTable = foreignTable;
	}

	public  void setEnabled(short enabled) {
		this.enabled = enabled;
	}

	@Override
	public String toString() {
		return "("+getId()+") content:"+content+" table:"+foreignTable+"->("+foreignId+")";
		}
	
	/** get JSP-based redirect page */
	public String redirectPage()
		{	
		final String prefix="redirect:/db/";
		if("bloodsample".equals(this.getForeignTable())) return prefix+"bloodsamples/show/"+this.getForeignId();
		return "404";
		}
	}
